package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArRegion;
import net.sk.china.city.service.IArRegionService;

/**
 * 网格Controller
 * 
 * @author yxf
 * @date 2024-05-28
 */
@Api(tags = "网格管理")
@RestController
@RequestMapping("/Region/region")
public class ArRegionController extends BaseController
{
    @Autowired
    private IArRegionService arRegionService;

    /**
     * 查询网格树状结构信息
     */
    @ApiOperation("查询网格树状结构信息")
    @PreAuthorize("hasAnyAuthority('Region:region:list')")
    @GetMapping("/tree")
    public AjaxResult tree(ArRegion arRegion)
    {

        return AjaxResult.success(arRegionService.selectArRegionTreeList(arRegion));
    }

    /**
     * 查询网格树状结构信息
     */
    @ApiOperation("无权限查询网格树状结构信息")
    @GetMapping("/treeAny")
    public AjaxResult treeAny()
    {
        return AjaxResult.success(arRegionService.selectArRegionTreeList(null));
    }

    /**
     * 导出网格列表
     */
    @PreAuthorize("hasAnyAuthority('Region:region:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArRegion arRegion)
    {
        List<ArRegion> list = arRegionService.selectArRegionList(arRegion);
//        ExcelUtil<ArRegion> util = new ExcelUtil<ArRegion>(ArRegion.class);
//        util.exportExcel(response, list, "网格列表数据");
    }

    /**
     * 获取网格详细信息
     */
    @PreAuthorize("hasAnyAuthority('Region:region:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(arRegionService.selectArRegionByPkId(pkId));
    }

    /**
     * 新增网格
     */
    @ApiOperation("新增网格列表")
    @PreAuthorize("hasAnyAuthority('Region:region:add')")
    @PostMapping
    public AjaxResult add(@RequestBody @Valid ArRegion arRegion)
    {
        return toAjax(arRegionService.insertArRegion(arRegion));
    }

    /**
     * 修改网格
     */
    @ApiOperation("修改网格")
    @PreAuthorize("hasAnyAuthority('Region:region:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArRegion arRegion)
    {
        return toAjax(arRegionService.updateArRegion(arRegion));
    }

    /**
     * 删除网格
     */
    @ApiOperation("删除网格")
    @PreAuthorize("hasAnyAuthority('Region:region:remove')")
	@DeleteMapping("/{pkId}")
    public AjaxResult remove(@PathVariable Long pkId)
    {
        return toAjax(arRegionService.deleteArRegionByPkId(pkId));
    }
}
